<template>
  <div :id="id" ref="boxwrap" :class="className" :style="{height:height,width:width}" :ctitle="ctitle" />
</template>

<script>
import resize from '@/components/Charts/mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '200px'
    },
    height: {
      type: String,
      default: '200px'
    },
    ctitle: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      chart: null,
      fontColor: '#bebebe',
      color: ['deepskyblue', 'orange', 'purple']
    }
  },
  mounted() {
    this.domResize()
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(document.getElementById(this.id))

      this.chart.setOption({
        color: this.color,
        title: {
          text: this.ctitle,
          top: 0,
          left: 'center',
          textStyle: {
            fontSize: 16,
            color: this.fontColor
          }
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          show: false,
          orient: 'vertical',
          top: '3%',
          right: '1%',
          textStyle: {
            fontSize: 14,
            color: this.fontColor
          }
        },
        radar: {
          radius: 60,
          center: ['50%', '55%'],
          indicator: [
            { name: '板厚', max: 6500 },
            { name: '尺寸', max: 16000 },
            { name: '线距', max: 30000 },
            { name: '线宽', max: 38000 },
            { name: '铜厚', max: 52000 }
          ]
        },
        series: [{
          name: '',
          type: 'radar',
          data: [
            {
              value: [4200, 3000, 20000, 35000, 50000, 18000],
              name: ''
            }
          ]
        }]
      })
    },
    domResize() {
      const that = this
      const dom = this.$refs.boxwrap
      this.$erd.listenTo(dom, function(element) {
        that.chart.resize()
      })
    }
  }
}
</script>
